<template>
  <base-page-view class-name="page-container to-app-container">
    <b-image v-if="isInWeChat" class-name="bg" src="/static/images/app/toApp/bg_weChat.jpg" mode="aspectFill" :is-asset="true" />
    <b-image v-else class-name="bg" src="/static/images/app/toApp/bg_browse.jpg" mode="aspectFill" :is-asset="true" @click="openApp(true)" />
  </base-page-view>
</template>
<script>
import CallApp from 'callapp-lib'
import './index.scss'
export default {
  name: 'AppPay',
  data() {
    return {
      isInWeChat: true,
      showOpenBrowserMenu: true,
      options: {
        scheme: {
          protocol: 'bixuan'
        },
        intent: {
          package: 'com.bisinuolan.app',
          scheme: 'bixuan'
        },
        appstore: 'https://itunes.apple.com/cn/app/id1243270000', // apple store
        yingyongbao: 'https://android.myapp.com/myapp/detail.htm?apkName=com.bisinuolan.app&ADTAG=mobile', // 应用宝
        fallback: 'https://android.myapp.com/myapp/detail.htm?apkName=com.bisinuolan.app&ADTAG=mobile', // 唤端失败后跳转的地址
        timeout: 10000
      },
      params: {}
    }
  },
  onLoad(options) {
    this.params = options
    // #ifdef H5
    this.isInWeChat = this.$Bridge.isInWeChat
    if (!this.$Bridge.isInWeChat) {
      this.openApp()
    } else {
      // uni.showToast({
      //   title: '请点击右上角，在自带浏览器打开',
      //   icon: 'none',
      //   duration: 3000
      // })
    }
    // #endif
  },
  methods: {
    openApp(flag) {
      // #ifdef H5
      if (this.$Bridge.isInWeChat) {
        uni.showToast({
          title: '请点击右上角，在自带浏览器打开',
          icon: 'none',
          duration: 3000
        })
        this.options.duration = 1000 * 60 * 24
      } else if (flag) {
        uni.showLoading({
          title: '打开中...'
        })
      }
      // #endif
      const callLib = new CallApp(this.options)
      callLib.open({
        param: this.params
        // callback: () => {
        //   location.href = 'https://android.myapp.com/myapp/detail.htm?apkName=com.bisinuolan.app&ADTAG=mobile'
        // }
      })
    }
  }
}
</script>
